from PySide6.QtCore import QThread, Signal

from ServiceController import ServiceController


class ControllerThread(QThread):
    result = Signal(dict)
    download_finished = Signal(dict)
    finished = Signal()
    def __init__(self, service_controller: ServiceController):
        super().__init__()
        self.service_controller = service_controller

    def run(self):
        self.service_controller.result.connect(self.result_callback)
        self.service_controller.finished.connect(self.finished_callback)
        self.service_controller.download_finished.connect(self.download_finished_callback)
        self.service_controller.exec()

    def download_finished_callback(self, result: dict):
        self.download_finished.emit(result)

    def finished_callback(self):
        self.finished.emit()

    def result_callback(self, result: dict):
        self.result.emit(result)
